var  Extend = function(des, src, override){
	var i = 0,l = 0,k = null;
	if ( src instanceof Array ) {
		for ( i = 0, l = src.length; i < l; i++ ) {
			Extend(des, src[i], override);
		}
	} else {
		for ( k in src ) {
			if ( override || !(k in des) ) {
				des[k] = src[k];
			}
		}
	}
	return des;
}
var Base = {
	    is: function(type) {
	        var self = this;
	        while (self) {
	            if (self == type) return true;
	            self = self.__type__; // __type__ : (1)Class-引用其父类 (2)New-实例所属的类
	        }
	        return false;

	    }
	};
var Class = function(DefineClass, BaseClass) {
	    var parent = BaseClass || Base,
	    _class = function() {
	        this.__type__ = parent;
	        for (var member in DefineClass) {
	            this[member] = DefineClass[member];
	        }

	    };
	    _class.prototype = parent;
	    return new _class();

};

var ZSHWEIXIN = Class({
	ajax: function(options){
		var self = this;
		// 默认配置
		var config = {
			url : "",//地址
			type : 'post', //请求类型
			dataType : 'json', //返回数据类型
			data : "", //ajax其他删除
			onSuccess : null, // 回调成功
			onError : null, // 失败
			onBefore : null //之前
		};
		// 重置配置
		var setting = Extend( config, options||{}, true );
		$.ajax({
            url: setting.url,
            type: setting.type,
            dataType: setting.dataType,
            data: setting.data,
            success:function(ret){
				if( typeof setting.onSuccess === 'function' ) {
					setting.onSuccess(ret);
				}
            },
            beforeSend: function () {
               if( typeof setting.onBefore === 'function' ) {
					setting.onBefore();
				}
            },
           error: function(XMLHttpRequest, textStatus, errorThrown) {
				if( typeof setting.onError === 'function' ) {
					setting.onError();
				}
            }
        });
	}
});

$.goUrl = function(url){
	window.location.href=url;
};

$(function(){
	/**
	 * artDialog删除提示框
	 * @param title
	 * @param content
	 * @param url
	 */
	$.dialogDel = function (title,content,url ){
		$.d = dialog({
			title: title,
			content: content,
			fixed: true,
			okValue:'确  定',
			ok: function(){
				$.get(url);
				window.location.href = url;
			}
		});
		$.d.showModal();
	};

	/*
	 *
	 * title 信息标题
	 * width   宽度
	 * height  高度
	 * url    ajax获取内容的地址
	 */
	$.dialogAjax = function (title,url,width,height){
		$.d = dialog({
			title: title,
			content: "正在载入...",
			fixed: true,
			width: width,
			height: height
		});
		$.d.showModal();

		$.ajax({
			type: "GET",
			url: url,
			dataType: 'html',
			success: function( data ){
				$.d.content( data );
			}
		});
	};

	/*
	 * title 	标题
	 * msg   	提示消息
	 * callback 自定义返回函数
	 */
	$.dialogMsg = function (title,msg,callback){
		$.d = dialog({
			title: title,
			content: msg,
			okValue: '确 定',
			ok: function(){
				if(callback){
					callback.call($(this));
				}
				this.close();
				return false;
			}
		});
		$.d.showModal();
	};

	$.dialogClose = function() {
		$.d.close();
	};



	//清除dialog 原因在于 dialog中ajax 第一次请求之后 ，保留了大量的缓存需要清除
	$.dialogRemove = function(){
		$.d.remove();
	}
	
	//关闭dialog
	$.dialogCloseTrue = function(){
		$.dialogClose();
		$.dialogRemove();
	}
	
});